<!--对账批次明细-->
<!--对账明细查询-->
<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="对账批次" prop="batchNo">
        <el-input
          v-model="queryParams.batchNo"
          placeholder="请输入对账批次"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="渠道名称" prop="tradeQudao">
        <el-input
          v-model="queryParams.tradeQudao"
          placeholder="请输入渠道名称：拉卡拉 交易渠道：暂时固定拉卡拉。"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="交易结果" prop="tradeResult">
        <el-select v-model="queryParams.tradeResult" placeholder="请选择">
          <el-option
            v-for="item in tradeResults"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="交易金额" prop="amount">
        <el-input
          v-model="queryParams.amount"
          placeholder="请输入交易金额：支付订单金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="交易日期" prop="tradeDateZf">
        <el-date-picker clearable
                        v-model="queryParams.startTradeDateZf"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择发起交易日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="----" prop="tradeDateZf">
        <el-date-picker
          v-model="queryParams.endTradeDateZf"
          type="date"
          clearable
          value-format="yyyy-MM-dd"
          @keyup.enter.native="handleQuery"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="支付方式" prop="payWay">
        <el-select v-model="queryParams.payWay" placeholder="请选择">
          <el-option
            v-for="item in payWays"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="是否差错" prop="hasDiff">
        <el-select v-model="queryParams.hasDiff" placeholder="请选择">
          <el-option
            v-for="item in hasDiffs"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="处理结果" prop="processState">
        <el-select v-model="queryParams.processState" placeholder="请选择">
          <el-option
            v-for="item in processStates"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">

      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['detail:detail:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="detailList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="对账批次" align="center" prop="batchNo" />
      <el-table-column label="交易流水号" align="center" width="165"  prop="payOrderNo" />
      <el-table-column label="渠道订单号" align="center" width="165" prop="qudaoOrderNo" />
      <el-table-column label="渠道名称" align="center" prop="tradeQudao" />
      <el-table-column label="记账凭证" align="center" prop="certificateJz" />
      <el-table-column label="对账凭证" align="center" prop="certificateDz" />
      <el-table-column label="交易结果" align="center" width="65" prop="tradeResult" >
        <template slot-scope="scope">
          <span v-if="scope.row.tradeResult == 1">处理中</span>
          <span v-if="scope.row.tradeResult == 2">成功</span>
          <span v-if="scope.row.tradeResult == 3">失败</span>
        </template>
      </el-table-column>
      <el-table-column label="交易金额" align="center" prop="amount" />
      <el-table-column label="订单金额" align="center" prop="amountOrder" />

      <el-table-column label="交易日期" align="center" width="165" prop="tradeDateZf" />
      <el-table-column label="手续费" align="center" prop="commissionFee" />
      <el-table-column label="支付方式" align="center" prop="payWay" >
        <template slot-scope="scope">
          <span v-if="scope.row.payWay == 1">微信扫码</span>
          <span v-if="scope.row.payWay == 2">支付宝扫码</span>
          <span v-if="scope.row.payWay == 3">微信公众号</span>
          <span v-if="scope.row.payWay == 4">认证支付</span>
          <span v-if="scope.row.payWay == 5">代付到银行卡</span>
        </template>
      </el-table-column>
      <el-table-column label="交易账户" align="center" prop="tradeAccount" />
      <el-table-column label="交易账户类型" align="center" prop="tradeAccountType" />
      <el-table-column label="对账完成时间" align="center" prop="checkEndDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.checkEndDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>

      <el-table-column label="是否差错" align="center" prop="hasDiff" >
        <template slot-scope="scope">
          <span v-if="scope.row.hasDiff == 0">否</span>
          <span v-if="scope.row.hasDiff == 1">是</span>
        </template>
      </el-table-column>
      <el-table-column label="差错处理结果：" align="center" prop="processState" >
        <template slot-scope="scope">
          <span v-if="scope.row.processState == 1">未处理</span>
          <span v-if="scope.row.processState == 2">要结算</span>
          <span v-if="scope.row.processState == 3">不结算</span>
          <span v-if="scope.row.processState == 4">已处理</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <!--            v-if="scope.row.processState == 1"-->
          <el-button
            v-if="scope.row.processState==1"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['detail:detail:edit']"
          >差错处理</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listDetail, selectDetailByOrder, delDetail, addDetail, updateDetail } from "@/api/property/detail";

export default {
  name: "Detail",
  data() {
    return {
      flagStatus:false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 对账批次明细表格数据
      detailList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //交易结果
      tradeResults: [
         {value: 1, label: '处理中'}
        ,{value: 2, label: '成功'}
        ,{value: 3, label: '失败'},
      ],
      //支付方式
      payWays:[
        {value: 1, label: '微信扫码'},
        {value: 2, label: '支付宝扫码'},
        {value: 3, label: '微信公众号'},
        {value: 4, label: '认证支付'},
        {value: 5, label: '代付到银行卡'},
      ],
      //是否差错
      hasDiffs:[{value: 0, label: '否'  },{value: 1,label: "是"}],
      //处理结果
      processStates:[
        {value:1,label:"未处理"},
        {value:2,label:"要结算"},
        {value:3,label:"不结算"},
        {value:4,label:"已处理"},
      ],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        billDay: null,
        checkDay: null,
        batchId: null,
        batchNo: null,
        payOrderNo: null,
        qudaoOrderNo: null,
        tradeQudao: null,
        certificateJz: null,
        certificateDz: null,
        tradeResult: null,
        amount: null,
        tradeDateZf: null,
        commissionFee: null,
        payWay: null,
        tradeAccount: null,
        tradeAccountType: null,
        checkEndDate: null,
        hasDiff: null,
        processState: null,
        completeState: null,
        confirmDate: null,
        canClearingAmount: null,
        remarks: null,
        delFlg: null,
        createUserid: null,
        updateUserid: null,
      },
      // 表单参数
      form: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询对账批次明细列表 */
    getList() {
      this.queryParams.batchNo=this.$route.params.batchNo;
      this.loading = true;
      listDetail(this.queryParams).then(response => {
        this.detailList = response.rows;
        this.total = response.total;
        this.loading = false;
      });

    },
    //是否显示差错处理
    flag(row){

    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        billDay: null,
        checkDay: null,
        batchId: null,
        batchNo: null,
        payOrderNo: null,
        qudaoOrderNo: null,
        tradeQudao: null,
        certificateJz: null,
        certificateDz: null,
        tradeResult: null,
        amount: null,
        tradeDateZf: null,
        commissionFee: null,
        payWay: null,
        tradeAccount: null,
        tradeAccountType: null,
        checkEndDate: null,
        hasDiff: null,
        processState: null,
        completeState: null,
        confirmDate: null,
        canClearingAmount: null,
        remarks: null,
        reserve1: null,
        reserve2: null,
        reserve3: null,
        reserve4: null,
        reserve5: null,
        delFlg: null,
        createUserid: null,
        createTime: null,
        updateUserid: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加对账批次明细";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      if(row.amount!=row.amountOrder){
        this.$message("金额不一致")
        updateDetail(row).then(response => {
          this.form = response.data;
        });
      }
      updateDetail(row).then(response => {
        this.form = response.data;
      });
       /* selectDetailByOrder(row).then(response => {
          this.form = response.data;
        });*/


      /*updateDetail(row.id).then(response => {
        this.form = response.data;
        this.title = "差错处理";
      });*/
      this.getList();
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除对账批次明细编号为"' + ids + '"的数据项？').then(function() {
        return delDetail(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('detail/detail/export', {
        ...this.queryParams
      }, `detail_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
